from logging import StreamHandler
from confluent_kafka import Producer


class KafkaStream:
    def __init__(self, bootstrap_server, topic):
        print(bootstrap_server, topic)
        self.producer = Producer({"bootstrap.servers": bootstrap_server})
        self.topic = topic

    def flush(self):
        self.producer.flush()

    def write(self, message):
        self.producer.produce(self.topic, message)


class KafkaHandler(StreamHandler):
    def __init__(self, bootstrap_server, topic):
        stream = KafkaStream(bootstrap_server, topic)
        super().__init__(stream)
